#include "HealthCondition.h"
#include "CombatComponent.h"
#include "CombatResponse.h"
#include "Game.h"

REGISTEREFFECT(HealthCondition, Create);

const HashedString HealthCondition::type("Permanent");

Pointer<Combat::IEffect> HealthCondition::Create( Combat::Combatant* owner )
{
	Pointer<Combat::IEffect> effect = new HealthCondition(owner);

	return effect;
}

HealthCondition::HealthCondition( Combat::Combatant* owner ) : Combat::IEffect(owner)
{
}

const HashedString& HealthCondition::Type()
{
	return type;
}

void HealthCondition::OnPostDefend( Combat::Response& response )
{
	Subject<int>& health = m_owner->Health();
	int totalDamage = response.physicalDamage + response.specialDamage + response.trueDamage;

	if ((health.getObject() - totalDamage) <= 0)
	{
		Game::getSingleton().RemoveController(m_owner->Parent());
		Game::getSingleton().RemoveEntityFromAllGroups(m_owner->Parent());
		Game::getSingleton().RemoveEntity(m_owner->Parent());
	}
}